package bank.driver.local;

import java.io.IOException;

import bank.Account;
import bank.InactiveException;
import bank.OverdrawException;

public class LocalAccount implements Account {

	private boolean active;
	private String owner;
	private int number;
	private double balance;
	
	public LocalAccount(String owner, int number){
		this.owner = owner;
		this.number = number;
		this.active = true;
	}

	/**
	 * "einzahlen"
	 */
	@Override
	public void deposit(double amount) throws IOException,
			IllegalArgumentException, InactiveException {
		if (amount <= 0) {
			throw new IllegalArgumentException();
		}
		if (!isActive()){
			throw new InactiveException();
		}
		this.balance += amount;
	}

	@Override
	public double getBalance() throws IOException {
		return this.balance;
	}

	@Override
	public String getNumber() throws IOException {
		return String.valueOf(this.number);
	}

	@Override
	public String getOwner() throws IOException {
		return this.owner;
	}

	@Override
	public boolean isActive() throws IOException {
		return this.active;
	}

	/**
	 * "abheben"
	 */
	@Override
	public void withdraw(double amount) throws IOException,
			IllegalArgumentException, OverdrawException, InactiveException {
		if (amount < 0) {
			throw new IllegalArgumentException();
		}
		if (!isActive()){
			throw new InactiveException();
		}
		if (this.balance-amount < 0){
			throw new OverdrawException();
		}
		this.balance -= amount;
	}

	public void deactivate() {
		this.active = false;
	}

}
